<template>
  <div class="dashboard-container" v-loading="loading">
    <!-- 卡片视图区域 -->
    <el-card class="box-card">
      <!-- alert警告区域 -->
      <el-alert :title="alertText" type="info" show-icon :closable="false" class="alert"> </el-alert>
      <!-- 日志表格区域 -->
      <el-table :data="logsList" stripe style="width: 100%">
        <el-table-column align="center" prop="type" label="操作类型" width="180"> </el-table-column>
        <el-table-column align="center" prop="author" label="操作人" width="180"> </el-table-column>
        <el-table-column prop="title" label="执行结果"> </el-table-column>
        <el-table-column align="center" prop="display_time" label="操作时间"> </el-table-column>
        <el-table-column align="center" prop="forecast" label="描述" width="180"> </el-table-column>
      </el-table>
      <!-- 分页区域 -->
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="queryInfo.page"
        :page-sizes="[10, 20, 30, 50]"
        :page-size="queryInfo.limit"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
        background
      >
      </el-pagination>
    </el-card>
  </div>
</template>
<script>
import { list } from '@/api/example/table'
export default {
  name: 'base-logs',
  data () {
    return {
      // loading加载
      loading: false,
      // listLoading: true,
      // alert警告内容
      alertText: '',
      // 日志数据列表
      logsList: [],
      // 分页数据
      queryInfo: {
        // 请求页数
        page: 1,
        // 每页请求条数
        limit: 20
      },
      // 总页数
      total: 0
    }
  },
  created () {
    this.getLogsList()
  },
  methods: {
    async getLogsList () {
      this.loading = true
      try {
        const { data } = await list(this.queryInfo)
        console.log(data)
        console.log(this.queryInfo)
        this.logsList = data.items
        this.total = data.total
        this.alertText = `共 ${this.total} 条记录`
        this.loading = false
      } catch (error) {
        this.$message('获取数据失败')
        this.loading = false
      }
    },
    // 每页显示的条数变更以后触发
    handleSizeChange (newSize) {
      this.queryInfo.limit = newSize
      this.getLogsList()
    },

    // 当前页码发生改变时触发
    handleCurrentChange (newPage) {
      this.queryInfo.page = newPage
      this.getLogsList()
    }
  }
}
</script>
<style lang="scss" scoped>
.dashboard-container {
  .box-card {
    margin: 20px;
    .alert {
      margin-bottom: 20px;
    }
    .el-table {
      .el-table-column {
        padding: 10px 0;
      }
    }
  }
  .el-pagination {
    margin-top: 20px;
    float: right;
  }
}
</style>
